package command;

import common.ParseException;
import file.FileString;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Command extends Cmd {

    private String labelString;
    private String paramsString;

    protected Command(FileString parentFileString) throws ParseException {
        super(parentFileString);

        Pattern pattern = Pattern.compile("[A-Za-z0-9-_]*");
        Matcher matcher = pattern.matcher(parentFileString.getCommand());

        if (matcher.find()) {
            paramsString = parentFileString.getCommand().substring(parentFileString.getCommand().indexOf(':') + 1).trim();
            labelString = matcher.group().trim();
        } else
            throw new ParseException(parentFileString, "Строка ошибочно распознана как Command");
    }

    @Override
    public Cmd getCopy() throws ParseException {
        Command tCmd = new Command(getParentFileString().getCopy());
        for (Cmd ttCmd : getBody())
            tCmd.addCmdToBody(ttCmd.getCopy());
        return tCmd;
    }

    public String getLabelString() {
        return labelString;
    }

    public String getParamsString() {
        return paramsString;
    }
}
